package com.etop.weibo.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.beanutils.Converter;

/**
 *
 * @author jansing lz_jansing@163.com
 */
public class DateConverter implements Converter {

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Override
    public Object convert(Class type, Object o) {
        if (type != Date.class) {
            return null;
        }
        try {
            if (o instanceof String) {
                return sdf.parse((String) o);
            }
        } catch (ParseException ex) {
            Logger.getLogger(DateConverter.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

}
